﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WMSUIMVC.Aubit.Procurement;
using WMSUIMVC.DTO.Injure;
using XuanKeZz.Application.HTTP;

namespace WMSUIMVC.Controllers
{
    public class InjureController : Controller
    {

        private readonly IConfiguration configuration;

        public InjureController(IConfiguration configuration)
        {
            this.configuration = configuration;
        }

        public IActionResult Index()
        {
            return View();
        }


        public IActionResult AddInjure()
        {
            return View();
        }

        public IActionResult GetInjure()
        {
            return View();
        }

        public IActionResult UpdInjure()
        {
            return View();
        }


        /// <summary>
        /// 添加报损管理
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> AddInjureList(AddInjureDto obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = configuration["Url"] + "ckx/api/Injure/AddInjure";
            string list = JsonConvert.SerializeObject(obj);
            string res = await client.PostAsync(url, list);
            return Json(res);
        }


        /// <summary>
        /// 显示报损的数据
        /// </summary>
        /// <param name="model"></param>
        /// <param name="pindex"></param>
        /// <param name="psize"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetInjureList(InjureListDto obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = configuration["Url"] + "ckd/api/Injure/GetStoreList?InjureCode=" + obj.InjureCode + "&InjureType=" + obj.InjureType + "&AuditStart=" + obj.AuditStart + "&pageIndex=" + obj.Pindex + "&PageSize=" + obj.Psize;
            string res = await client.GetAsync(url); 
            return Json(res);
        }

        /// <summary>
        /// 查看报损详情数据
        /// </summary>
        /// <param name="model"></param>
        /// <param name="pindex"></param>
        /// <param name="psize"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetInjureDetail(FanInjureDto obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = configuration["Url"] + "ckd/api/Injure/GetStoreDetail?InProductId=" + obj.InProductId;
            string res = await client.GetAsync(url);
            return Json(res);
        }

        /// <summary>
        /// 反填损的数据
        /// </summary>
        /// <param name="model"></param>
        /// <param name="pindex"></param>
        /// <param name="psize"></param>
        /// <returns></returns>
        public async Task<IActionResult> FanInjureList(FanInjureDto obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = configuration["Url"] + "ckd/api/Injure/FanStoreList?InProductId=" + obj.InProductId;
            string res = await client.GetAsync(url);
            return Json(res);
        }


        /// <summary>
        /// 修改报损管理
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> UpdInjureList(AddInjureDto obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = configuration["Url"] + "ckx/api/Injure/UpdInjure";
            string list = JsonConvert.SerializeObject(obj);
            string res = await client.PostAsync(url, list);
            return Json(res);
        }


        /// <summary>
        /// 操作删除采购
        /// </summary>
        /// <param name="model"></param>
        /// <param name="pindex"></param>
        /// <param name="psize"></param>
        /// <returns></returns>
        public async Task<IActionResult> DelInjure(DelInjureDto obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = configuration["Url"] + "ckx/api/Injure/DelInjure";
            //转成集合
            var list = "{\"inProductId\":" + JsonConvert.SerializeObject(obj.InProductId) + "}";
            //将集合转成json
            var res = await client.PutAsync(url, list);
            return Json(res);
        }


        /// <summary>
        /// 审核报损管理
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> AuditInjure(AuditInjureDto obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = configuration["Url"] + "ckx/api/Injure/UpdStateInjure?AuditStart=" + obj.AuditStart+ "&AuditResult="+ obj.AuditResult + "&InProductId=" + obj.InProductId;
            string list = JsonConvert.SerializeObject(obj);
            string res = await client.PostAsync(url, list);
            return Json(res);
        }




    }
}
